package com.example.rbacmanage.controller.background;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.app.Photo;
import com.example.rbacmanage.entity.app.PhotoFrame;
import com.example.rbacmanage.service.app.PhotoFrameService;
import com.example.rbacmanage.service.app.PhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@RestController
@RequestMapping("/background/photoframe")
public class PhotoFrameController {
    @Autowired
    private PhotoFrameService photoFrameService;

    @GetMapping("/list")
    @PreAuthorize("hasAnyAuthority('background:photoframe:list')")
    public Result page(PhotoFrame photoFrame){
        return Result.success(photoFrameService.getPage(photoFrame));
    }

    @PreAuthorize("hasAnyAuthority('background:photoframe:add')")
    @PostMapping("/add")
    public Result add(@RequestBody PhotoFrame photoFrame){
        photoFrame.setCreateTime(new Date());
        photoFrameService.save(photoFrame);
        return Result.success();
    }
    @PreAuthorize("hasAnyAuthority('background:photoframe:update')")
    @PutMapping("/update")
    public Result update(@RequestBody PhotoFrame photoFrame){
        photoFrameService.update(photoFrame);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('background:photoframe:remove')")
    @DeleteMapping("/remove")
    public Result remove(@RequestBody Long[] ids){
        photoFrameService.remove(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Long id){
        return Result.success(photoFrameService.getById(id));
    }
}
